#include "loScriptMove.hpp"
#include "loScriptMoveRandom.hpp"

loScriptMoveRandom::loScriptMoveRandom()
  : edaMoveGen(),
    from_(0),
    to_(0)
{
}

loScriptMoveRandom::loScriptMoveRandom( int from, int to )
  : edaMoveGen(),
    from_(from),
    to_(to)
{
}

loScriptMoveRandom::loScriptMoveRandom( const loScriptMoveRandom &m )
  : edaMoveGen(m),
    from_(m.from_),
    to_(m.to_)
{
}

loScriptMoveRandom::~loScriptMoveRandom()
{
}

edaMoveGen *loScriptMoveRandom::clone() const
{
  return new loScriptMoveRandom(*this);
}

bool loScriptMoveRandom::generate(edaMove *move, const edaSolution &sol)
{
  loScriptMove *mymove = (loScriptMove *)move;
  int sid = from_ + rng.random( to_-from_ );
  mymove->setScript( sid );

  return true;
}

void loScriptMoveRandom::Serialize(edaBuffer &buf, bool pack)
{
  if (pack)
  {
    buf.Pack( &from_, 1 );
    buf.Pack( &to_, 1 );
  }
  else
  {
    buf.UnPack( &from_, 1 );
    buf.UnPack( &to_, 1 );
  }
}
